package com.ruoyi.peoplegroup.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.peoplegroup.domain.Partnerprojects;
import com.ruoyi.peoplegroup.service.IPartnerprojectsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 合作单位关联的科研项目Controller
 * 
 * @author gw
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/partnerprojects")
public class PartnerprojectsController extends BaseController
{
    @Autowired
    private IPartnerprojectsService partnerprojectsService;

    /**
     * 查询合作单位关联的科研项目列表
     */
    @RequiresPermissions("peoplegroup:partnerprojects:list")
    @GetMapping("/list")
    public TableDataInfo list(Partnerprojects partnerprojects)
    {
        startPage();
        List<Partnerprojects> list = partnerprojectsService.selectPartnerprojectsList(partnerprojects);
        return getDataTable(list);
    }

    /**
     * 导出合作单位关联的科研项目列表
     */
    @RequiresPermissions("peoplegroup:partnerprojects:export")
    @Log(title = "合作单位关联的科研项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Partnerprojects partnerprojects)
    {
        List<Partnerprojects> list = partnerprojectsService.selectPartnerprojectsList(partnerprojects);
        ExcelUtil<Partnerprojects> util = new ExcelUtil<Partnerprojects>(Partnerprojects.class);
        util.exportExcel(response, list, "合作单位关联的科研项目数据");
    }

    /**
     * 获取合作单位关联的科研项目详细信息
     */
    @RequiresPermissions("peoplegroup:partnerprojects:query")
    @GetMapping(value = "/{partnerProjectId}")
    public AjaxResult getInfo(@PathVariable("partnerProjectId") Long partnerProjectId)
    {
        return success(partnerprojectsService.selectPartnerprojectsByPartnerProjectId(partnerProjectId));
    }

    /**
     * 新增合作单位关联的科研项目
     */
    @RequiresPermissions("peoplegroup:partnerprojects:add")
    @Log(title = "合作单位关联的科研项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Partnerprojects partnerprojects)
    {
        return toAjax(partnerprojectsService.insertPartnerprojects(partnerprojects));
    }

    /**
     * 修改合作单位关联的科研项目
     */
    @RequiresPermissions("peoplegroup:partnerprojects:edit")
    @Log(title = "合作单位关联的科研项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Partnerprojects partnerprojects)
    {
        return toAjax(partnerprojectsService.updatePartnerprojects(partnerprojects));
    }

    /**
     * 删除合作单位关联的科研项目
     */
    @RequiresPermissions("peoplegroup:partnerprojects:remove")
    @Log(title = "合作单位关联的科研项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partnerProjectIds}")
    public AjaxResult remove(@PathVariable Long[] partnerProjectIds)
    {
        return toAjax(partnerprojectsService.deletePartnerprojectsByPartnerProjectIds(partnerProjectIds));
    }
}
